package comment.service.Imp;

import comment.dao.IUserDao;
import comment.dao.IVideoDao;
import comment.dao.imp.UserDaoImp;
import comment.dao.imp.VideoDaoImp;
import comment.model.pojo.Comment;
import comment.model.pojo.Reply;
import comment.model.pojo.User;
import comment.model.pojo.Video;
import comment.service.IVideoService;

import java.util.ArrayList;
import java.util.List;

public class VideoServiceImp implements IVideoService {
    private IUserDao  iUserDao=new UserDaoImp();
    private IVideoDao iVideoDao=new VideoDaoImp();


    @Override
    public void getAllinfoById(int id) throws IllegalAccessException, InstantiationException {
        List<Video> videos=new ArrayList<>();
        List<Comment> comments=new ArrayList<>();
        List<Reply> replies=new ArrayList<>();

        User user =iUserDao.getUserById(id);
        videos=iVideoDao.getVideoByUid(user.getId());
        System.out.println("id="+id+"顾客发布的视频"+videos);
        for (int i = 0; i < videos.size(); i++) {
            comments=iVideoDao.getCommentByVid(videos.get(i).getId());
            System.out.println("该视频下的评论："+comments);
            for (int j = 0; j < comments.size(); j++) {
                replies=iVideoDao.getReplyByCommentId(comments.get(j).getId());
                System.out.println("评论id="+comments.get(j).getId()+" 下的回复为："+replies);
            }
        }

    }

    @Override
    public void deleteByVid(int vid) throws IllegalAccessException, InstantiationException {
        iVideoDao.deleteVideoByVid(vid);
        List<Comment> comments=new ArrayList<>();
        comments=iVideoDao.getCommentByVid(vid);
        iVideoDao.deleteCommentBy(vid);
        for (int i = 0; i < comments.size(); i++) {
            iVideoDao.deleteReplyBy(comments.get(i).getId());
        }
    }


}
